package com.ihr360.payroll.service.payroll.convertor;

import com.google.common.collect.Lists;
import com.ihr360.commons.model.IConvertor;
import com.ihr360.payroll.config.reference.ReferencePropertyEntity;
import com.ihr360.payroll.model.dto.reference.ReferenceProperty;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

@Component
public class ReferencePropertyConvertor implements IConvertor<ReferencePropertyEntity, ReferenceProperty> {
    @Override
    public ReferenceProperty convertEntityToDto(ReferencePropertyEntity entity) {
        return null;
    }

    @Override
    public ReferencePropertyEntity convertDtoToEntity(ReferenceProperty dto) {
        ReferencePropertyEntity entity = new ReferencePropertyEntity();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }

    public Collection<ReferencePropertyEntity> convertDtosToEntitys(Collection<ReferenceProperty> dtos) {
        if (CollectionUtils.isEmpty(dtos)) {
            return Lists.newArrayList();
        }
        List<ReferencePropertyEntity> entities = Lists.newArrayListWithCapacity(dtos.size());
        dtos.forEach(dto ->{
            entities.add(convertDtoToEntity(dto));
        });
        return entities;
    }
}
